#include "mwidget.h"
#ifdef GUI_APPLICATION

#include "mapplication.h"
#include "mwindowmanager.h"
#include "kernelprivate.h"

MWidget::MWidget(MWidget *parent) :
	MObject(*new MWidgetPrivate(this), parent)
{
	d_func()->init();
	MWindowManager::uniqueObject()->newWindow(*this);
}

MWidget::~MWidget()
{

}

int MWidget::x() const
{
	return d_func()->rect.x();
}

int MWidget::y() const
{
	return d_func()->rect.y();
}

MPoint MWidget::point() const
{
	return MPoint(d_func()->rect.x(), d_func()->rect.y());
}

int MWidget::width() const
{
	return d_func()->rect.width();
}

int MWidget::height() const
{
	return d_func()->rect.height();
}

MSize MWidget::size() const
{
	return MSize(d_func()->rect.width(), d_func()->rect.height());
}

MString MWidget::windowTitle() const
{
	return d_func()->title;
}

int MWidget::attribute() const
{
	return d_func()->attr;
}

int MWidget::flags() const
{
	return d_func()->flags;
}

Jxq::WindowState MWidget::state() const
{
	return d_func()->state;
}

MColor MWidget::backgroundColor() const
{
	return d_func()->bcolor;
}

void MWidget::setVisible(bool visible)
{
	MWindowManager::uniqueObject()->setVisible(*this, visible);
}

void MWidget::show()
{
	MWindowManager::uniqueObject()->setVisible(*this);
}

void MWidget::hide()
{
	MWindowManager::uniqueObject()->setVisible(*this, false);
}

void MWidget::move(int x, int y)
{

}

void MWidget::move(const MPoint &point)
{

}

void MWidget::resize(int width, int height)
{

}

void MWidget::resize(const MSize &size)
{

}

void MWidget::setWindowTitle(const MString &text)
{
	d_func()->title = text.c_str();
	MWindowManager::uniqueObject()->setWindowTitle(*this);
}

bool MWidget::isHidden()
{

	return true;
}

bool MWidget::event(MEvent *event)
{
	if( MObject::event(event) )
		return true;
	switch(event->type())
	{
		case MEvent::Paint:{
			MPaintEvent *real_event = dynamic_cast<MPaintEvent*>(event);
			if( real_event != NONE )
				paintEvent(real_event);
		}return true;

		case MEvent::MouseMove:
			return true;

		case MEvent::MousePress:
			return true;

		case MEvent::MouseRelease:
			return true;

		case MEvent::MouseRight:
			return true;

		case MEvent::MouseDouble:
			return true;

		case MEvent::KeyBoardPress:
			return true;

		case MEvent::KeyBoardRelease:
			return true;

		case MEvent::Close:
			return true;

		default: return true;
	}
	return false;
}


#endif //GUI_APPLICATION
